//
//  MyTeamViewController.m
//  ShouYi
//
//  Created by yurui on 16/3/10.
//  Copyright © 2016年 yurui. All rights reserved.
//

#import "MyTeamViewController.h"
#import "TeamTableViewCell.h"
#define kBtImageArray @[@"icon_1bt.png", @"icon_2bt.png", @"icon_3bt.png"]
#define kBtTitleArray @[@"10", @"8", @"7"]
@interface MyTeamViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong) UIView *teamView;
@property(nonatomic,strong) UIView *aView;
@property(nonatomic,strong) UIButton *button;
@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) NSMutableArray *arr;
@property (nonatomic,strong)UIScrollView *scrollView;

@end

@implementation MyTeamViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.receiveIndex = 0;
    self.title = @"我的团队";
    // 取消导航条对scrollView的影响
    self.automaticallyAdjustsScrollViewInsets = NO;

    self.view.backgroundColor = kViewBackColor;
    [self addTeamView];
    [self configerTabelView];
}

- (void)addTeamView{
    //创建UIScrollerView
    self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, kWidth, 50)];
    // 设置要显示内容的大小
    _scrollView.contentSize = CGSizeMake(kWidth, 45);
    // 设置默认偏移量
    _scrollView.contentOffset = CGPointMake(0, 0);
    //
    _scrollView.backgroundColor = [UIColor whiteColor];
    self.arr = [@[@"一级队员  \n      10",@"二级队员  \n      10",@"三级队员  \n      10"]mutableCopy];
    for (int i = 0; i < _arr.count; i ++) {
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        self.button.frame = CGRectMake(kWidth / 3 * i, 0, kWidth / 3, 48);
        [self.button setTitle:_arr[i] forState:UIControlStateNormal];
        self.button.titleLabel.numberOfLines = 0;
        [self.button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self.button addTarget:self action:@selector(temaAction:) forControlEvents:UIControlEventTouchUpInside];
        self.button.titleLabel.font = [UIFont systemFontOfSize:13];
        self.button.tag = 1000 + i;
        [_scrollView addSubview:_button];
    }
    [self.view addSubview:_scrollView];
    UIView *labelView = [[UIView alloc]initWithFrame:CGRectMake(kWidth / 3 * self.receiveIndex + 20, 46, kWidth / 3 - 40, 2)];
    labelView.backgroundColor = [UIColor redColor];
    labelView.tag = 5555;
    [self.scrollView addSubview:labelView];
    
}
- (void)configerTabelView{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 124, kWidth, kHeight - 124 ) style:UITableViewStylePlain];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    self.tableView.backgroundColor = kViewBackColor;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[TeamTableViewCell class] forCellReuseIdentifier:@"cell"];

    [self.view addSubview:_tableView];
}
 //
- (void)temaAction:(UIButton *)sender{
    UIView *lv = [self.scrollView viewWithTag:5555];
    lv.frame = CGRectMake(kWidth / 3 * (sender.tag - 1000) + 10,46, kWidth / 3 - 20, 2);
    for (int i = 1000 ; i < 1000 + self.arr.count; i ++) {
        UIButton *bt = [self.scrollView viewWithTag:i];
        NSMutableArray *arr = [NSMutableArray array];
        [arr addObject:bt];
        for (UIButton *bb in arr) {
            [bb setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
        if (i == sender.tag) {
            [bt setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }else{
            [bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
        
    }
    
    [sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

}

- (void)viewWillAppear:(BOOL)animated{
    for (int i = 1000;  i < self.arr.count + 1000; i ++) {
        UIButton *bt = [self.scrollView viewWithTag:i];
        if ( i == self.receiveIndex + 1000) {
            [bt setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }else{
            [bt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        }
    }

}


- (void)teamData{
    NSLog(@"nil");
}
#pragma mark  UITableViewDelegate和UITableViewDataSource代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 64;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TeamTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = kViewBackColor;
    cell.imageview.image = [UIImage imageNamed:@"img_touxxxxx.png"];
    cell.niceName.text = @"哈哈";
    cell.time.text = @"2013-08-27";
    cell.inviter.text = [NSString stringWithFormat:@"邀请人:%@",@"AB兔兔"];
    cell.teamNum.text = [NSString stringWithFormat:@"团队%@人",@"45"];
    cell.expend.text = @"已消费：";
    cell.money.text = @"5720";
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
